﻿using Note.Model;
using Note.View;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Note
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private bool IsLoad { get; set; }

        public MainWindow()
        {
            InitializeComponent();
        }

        private void Main_Loaded(object sender, RoutedEventArgs e)
        {
            IsLoad = true;
            this.MainData.UpdateList();
            this.MainData.SelectChange += Select_Change;
        }

        private void Type_Text_Change(object sender, TextChangedEventArgs e)
        {
            if (IsLoad)
            {
                this.MainData.UpdateList(Note_Type.Text);
            }
        }

        private void Add_Note_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new EditNoteDialog()
            {
                Value = true
            };
            var result = dialog.ShowDialog();
            if (result == true)
            {
                this.MainData.UpdateList(Note_Type.Text);
            }
        }

        private void Select_Change(object sender, EventArgs e)
        {
            Note_Path.Text = (sender as NoteDetailModel)?.Path;
        }
    }
}
